﻿using System;
using System.Configuration;
using Token.Util;

namespace Token.Piker.Core.Security
{
    /// <summary>
    ///AuthzManagerFactory 的摘要说明
    /// </summary>
    public class AuthzManagerFactory
    {
        //不可实例化
        private AuthzManagerFactory()
        {
        }

        private static readonly string defaultManagerType = "Security.AuthzManager";
        private static IAuthzManager mgr = null;

        /// <summary>
        /// 获得实例
        /// </summary>
        /// <returns></returns>
        public static IAuthzManager Instance()
        {
            if (mgr == null)
            {
                string strType = ConfigurationManager.AppSettings["security.AuthzManager"] as string;

                if (string.IsNullOrEmpty(strType))
                {

                    strType = defaultManagerType;

                    LogHelper.Warn("未配置security.AuthzManager，将使用“security.AuthzManager”类作为权限验证管理器。");

                }

                mgr = Activator.CreateInstance(Type.GetType(strType, true)) as IAuthzManager;
            }
            
            return mgr;    
        }
    }
}
